//
//  DownLoadObjects.m
//  HB
//
//  Created by 陶秋安 on 16/3/28.
//  Copyright © 2016年 孙智慧. All rights reserved.
//

#import "DownLoadObjects.h"

//单例模式对象
DownLoadObjects *downLoadObjects=nil;

@implementation DownLoadObjects

#pragma mark 单例模式

+(DownLoadObjects *)sharedMyClass
{
    @synchronized(self){  //为了确保多线程情况下，仍然确保实体的唯一性
        
        if (!downLoadObjects) {
            downLoadObjects= [[self alloc] init]; //该方法会调用 allocWithZone
            
        }
    }
    return downLoadObjects;
}

+(id)allocWithZone:(NSZone *)zone
{
    
    @synchronized(self){
        
        if (!downLoadObjects) {
            
            downLoadObjects = [super allocWithZone:zone]; //确保使用同一块内存地址
            
            return downLoadObjects;
            
        }
        
    }
    
    return nil;
    
}

- (id)copyWithZone:(NSZone *)zone;
{
    
    //确保copy对象也是唯一
    return self;
    
}

-(void) del:(id)obj
{
    [_downLoadTask removeObject:obj];
    
    if(_delegate!=nil)
    {
        [_delegate del];
    }
}

-(void) setDelegate:(id<DownLoadObjectsDelDelegate>) delegate
{
    _delegate= delegate;
    
}

-(void) initArray
{
    _downLoadTask = [[NSMutableArray alloc] init];
}

@end
